<?php
/**
 * create to 2021/6/25 14:45
 */

namespace app\mainadmin\controller\Liveing;

use app\AdminController;
use app\mainadmin\model\LiveGiftsModel;
/**
 * 直播间用户管理
 * Class Index
 * @package app\store\controller
 */
class GIfts extends AdminController
{
    /*------------------------------------------------------ */
    //-- 优先执行
    /*------------------------------------------------------ */
    public function initialize(){
        parent::initialize();
        $this->Model = new LiveGiftsModel();
    }
    /*------------------------------------------------------ */
    //-- 主页
    /*------------------------------------------------------ */
    public function index() {
        if (input("p/d")&&input("p/d")>0) {
            return $this->getList(false);
        }
        $this->getList(true);
        return $this->fetch();
    }
    /*------------------------------------------------------ */
    //-- 获取列表
    //-- $runData boolean 是否返回模板
    /*------------------------------------------------------ */
    public function getList($runData = false) {
        $viewObj = [];
        $data = $this->getPageList($this->Model,$viewObj);
        $this->assign('data',$data);
        if ($runData == false){
            $data['content']= $this->fetch('mainadmin@liveing/gifts/list')->getContent();
            unset($data['list']);
            return $this->success('','',$data);
        }
        return true;
    }

    /*------------------------------------------------------ */
    //-- 删除
    /*------------------------------------------------------ */
    public function del(){
        $id = input('id',0,'intval');
        if ($id < 1){
            return $this->error('传参错误.');
        }
        $row = $this->Model->where('id',$id)->find();
        if (empty($row)){
            return $this->error('没有找到相关记录.');
        }
        $res = $this->Model->where('id',$id)->delete();
        if ($res < 1){
            return $this->error('操作失败.');
        }
        return $this->success('操作成功.');
    }
}